import axios from "axios";

const request = axios.create({
    baseURL: '/api',
    timeout: 5000,
    timeoutErrorMessage: '请求超时'
});


request.interceptors.request.use(config => {
    // if (localStorage.getItem('token')) {
    //     const Token = localStorage.getItem('token');
    //     config.headers.Authorization = `Bearer ${Token}`;
    // }
    return config
}, (error) => {
    return Promise.reject(error)
} )
request.interceptors.response.use(respone => { 
    if (respone.status === 401) { 
        localStorage.removeItem('token')
        window.location.href = '/login'
    }
    return Promise.resolve(respone.data)
} , error => {
    return Promise.reject(error)
}
)

export default request;